#include <cassert>

inline bool PeopleHistory::IsBusy(const int i_status) const
{
	return (m_status == i_status && m_isBusy);
}

inline const float PeopleHistory::GetTotalScoredGoalRatio() const
{
	const size_t totalPlayedMatch = GetTotalMatch(StatusPlayer);
	return (totalPlayedMatch == 0 ? -1.0f : static_cast<float>(GetTotalScoredGoal()) / static_cast<float>(totalPlayedMatch));
}

inline void PeopleHistory::addHistoryEntry(const PeopleHistoryRecord& record)
{
	m_records.push_back(record);
}

inline void PeopleHistory::SetBusy(const bool i_isBusy)
{
	m_isBusy = i_isBusy;
}

inline int PeopleHistory::GetStatus() const
{
	return m_status;
}

inline void PeopleHistory::SetStatus(const int i_status)
{
	m_status = i_status;
}

inline int PeopleHistory::GetStatus(const int i_numSeason) const
{
	if((m_startingYear == -1) || (i_numSeason < m_startingYear))
		return StatusRetired;
	if((m_playerRetirementYear == -1) || (i_numSeason < m_playerRetirementYear))
		return StatusPlayer;
	return StatusTrainer;
}

inline bool PeopleHistory::WasStatus(const int i_numSeason, const int i_status) const
{
	const int oldStatus = GetStatus(i_numSeason);
	return (oldStatus & i_status) != 0;
}

inline const int PeopleHistory::GetNumSeason(const int i_status) const
{
	if(i_status == StatusPlayerOrTrainer)
	{
		if(m_status != StatusRetired)
			return s_currentYear - m_startingYear + 1;
		return m_trainerRetirementYear - m_startingYear;
	}

	if(i_status == StatusPlayer)
	{
		if(m_status == StatusPlayer)
			return s_currentYear - m_startingYear + 1;
		return m_playerRetirementYear - m_startingYear;
	}

	if(i_status == StatusTrainer)
	{
		if(m_status == StatusPlayer)
			return 0;
		if(m_status == StatusTrainer)
			return s_currentYear - m_playerRetirementYear + 1;
		return m_trainerRetirementYear - m_playerRetirementYear;
	}

	return 0;
}

inline const int PeopleHistory::GetAge() const
{
	return s_currentYear - m_birthYear;
}

inline const int PeopleHistory::GetPlayerAge() const
{
	if(m_status == StatusPlayer)
		return GetAge();
	if(GetNumSeason(StatusPlayer) == 0)
		return 0;
	return m_playerRetirementYear - m_birthYear;
}

inline const int PeopleHistory::GetTrainerAge() const
{
	if(m_status == StatusTrainer)
		return GetAge();
	if(m_status == StatusPlayer || GetNumSeason(StatusTrainer) == 0)
		return 0;
	return m_trainerRetirementYear - m_birthYear;
}

inline const int PeopleHistory::GetNumHistoryEntry() const
{
	return static_cast<int>(m_records.size());
}

inline const PeopleHistoryRecord& PeopleHistory::GetRecord(int i_index) const
{
	return m_records[i_index];
}

inline const int PeopleHistory::GetRetirementYear(const int i_status) const 
{
	if(i_status == StatusPlayer)
		return m_playerRetirementYear;
	if((i_status & StatusTrainer) != 0)
		return m_trainerRetirementYear;
	assert(0);
	return -1;
}

inline const int PeopleHistory::GetRetirementAge(const int i_status) const
{
	if(i_status == StatusPlayer)
	{
		if(m_playerRetirementYear == -1)
			return -1;
		return m_playerRetirementYear - m_birthYear;
	}

	if((i_status & StatusTrainer) != 0)
	{
		if(m_trainerRetirementYear == -1)
			return -1;
		return m_trainerRetirementYear - m_birthYear;
	}

	assert(0);
	return -1;

}

inline void PeopleHistory::SetRetirementYear(const int i_status) 
{
	if(i_status == StatusPlayer)
	{
		m_playerRetirementYear = s_currentYear;
	}else if (i_status == StatusTrainer){
		m_trainerRetirementYear = s_currentYear;
	}else{
		assert(0);
	}
}

inline bool PeopleHistory::IsRetired() const 
{
	return m_status == StatusRetired;
}

inline bool PeopleHistory::IsPlayer() const 
{
	return m_status == StatusPlayer;
}

inline bool PeopleHistory::IsTrainer() const 
{
	return m_status == StatusTrainer;
}
